package com.itheima.Work01;

import com.itheima.reflect.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class work02 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //获取字节码对象
        Class clazz = Class.forName("com.itheima.Work01.Student01");
        //获取构造方法
        Constructor constructor = clazz.getDeclaredConstructor(String.class, int.class);
        //取消访问检查
        constructor.setAccessible(true);
        //创建对象
        Student01 stu = (Student01) constructor.newInstance("迪丽热巴", 21);
        //获取方法
        Method method = clazz.getDeclaredMethod("showInfo");
        //取消访问 检查
        method.setAccessible(true);
        //执行方法
        method.invoke(stu);
    }

}